package com.gccloud.design;

import com.gccloud.design.entity.ParameterConfigEntity;
import com.gccloud.design.service.ParameterConfigService;
import com.gccloud.design.vo.ParameterConfigVo;
import com.gccloud.starter.common.dto.SearchDTO;
import com.gccloud.starter.common.vo.R;
import com.gccloud.starter.core.vo.PageVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping("/api/parameterConfig")
@Api(tags = "设计中心API参数配置")
public class ParameterConfigController {

    @Resource
    private ParameterConfigService parameterConfigService;

    @ApiOperation(value = "新增接口配置")
    @PostMapping("/insert")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "param_name", value = "参数名称",dataType = "String", paramType = "path"),
//            @ApiImplicitParam(name = "param_code", value = "参数编码",dataType = "String", paramType = "path"),
//            @ApiImplicitParam(name = "field_type", value = "参数类型",dataType = "String", paramType = "path")
    })
    public R<Object> insert(@RequestBody ParameterConfigEntity parameterConfigEntity) {
        Integer num = parameterConfigService.insert(parameterConfigEntity);
        if (num==1){
            return R.success(num);
        }
       return R.error("添加数据失败");
    }

    @ApiOperation(value = "更新接口配置")
    @PostMapping("/update")
    @ApiImplicitParams({
//            @ApiImplicitParam(name = "param_name", value = "参数名称", required = true, dataType = "String", paramType = "path"),
//            @ApiImplicitParam(name = "param_code", value = "参数编码", required = true, dataType = "String", paramType = "path"),
//            @ApiImplicitParam(name = "field_type", value = "参数类型", required = true, dataType = "String", paramType = "path")
    })
    public R<Object> update(@RequestBody ParameterConfigEntity parameterConfigEntity) {
        Integer row = parameterConfigService.update(parameterConfigEntity);
        if (row==1){
            return R.success(row);
        }
       return R.error("更改数据失败");
    }

    @ApiOperation(value = "分页查询API参数配置")
    @GetMapping("/selectPage")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "current", value = "页码", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = "size", value = "每页条数", paramType = "query", required = true, dataType = "int"),
            @ApiImplicitParam(name = "searchKey", value = "查询条件", paramType = "query", dataType = "string")
    })
    public R<PageVO<ParameterConfigVo>> selectParameterConfigByPage(SearchDTO searchDTO) {
        PageVO<ParameterConfigVo> pageVO=parameterConfigService.selectByPage(searchDTO);
        return R.success(pageVO);
    }

    @ApiOperation(value = "批量删除接口配置")
    @PostMapping("/deleteBatchIds")
    public R<Object> deleteBatchIds(@RequestBody List<Integer> ids){
       boolean flag= parameterConfigService.delete(ids);
       if (flag==true){
           return R.success(flag);
       }
       return R.error("批量删除失败");
    }
}

